package com.hnqcgczy.gp.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "NewLoginServlet",value = "/NewLoginServlet")
public class NewLoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //System.out.println("=======");
        //获取用户名和密码
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        //获取用户的意愿
        String[] checkboxes = request.getParameterValues("cb1");

        //根据用户的意愿来进行判断做相关的操作


        //创建Cookie
        Cookie cookie_name = new Cookie("uname", username);
        Cookie cookie_pwd = new Cookie("pwd", password);
        //设置存活时间
        cookie_name.setMaxAge(3*24*60*60);
        cookie_pwd.setMaxAge(3*24*60*60);

        //取消
      //  cookie_name.setMaxAge(0);
       // cookie_pwd.setMaxAge(0);

        //添加到响应头去
        response.addCookie(cookie_name);
        response.addCookie(cookie_pwd);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);

    }
}
